package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.NoticeFabulousBean;
import mamikeji.liaowa.widget.GlideCircleTransform;

/**
 * Created by Administrator on 2017/7/28 0028.
 */
public class NoticeFabulousAdapter extends BaseAdapter {
    private Context context;
    private List<NoticeFabulousBean.DataBean> list;
    private LayoutInflater inflater;

    public NoticeFabulousAdapter(Context context, List<NoticeFabulousBean.DataBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_notice_fabulous, viewGroup, false);
            holder = new ViewHolder();
            holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_avatar);
            holder.tv_nickname = (TextView) convertView.findViewById(R.id.tv_nickname);
            holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            holder.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
            holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        NoticeFabulousBean.DataBean bean = (NoticeFabulousBean.DataBean) getItem(i);
        Glide.with(context).load(bean.getAvatar()).dontAnimate().placeholder(R.drawable.icon_guanyuliaowa_n).transform(new GlideCircleTransform(context)).into(holder.iv_avatar);
        holder.tv_nickname.setText(bean.getNickname());
        holder.tv_time.setText(bean.getOperationtime());
        if (bean.getFccontenttype() == 1) {
            holder.iv_image.setVisibility(View.GONE);
            holder.tv_content.setVisibility(View.VISIBLE);
            holder.tv_content.setText(bean.getFccontent());
        } else {
            holder.iv_image.setVisibility(View.VISIBLE);
            holder.tv_content.setVisibility(View.GONE);
            String[] strings = bean.getFccontent().split(",");
            Glide.with(context).load(strings[0]).dontAnimate().placeholder(R.drawable.img_zhuantiliebiao).into(holder.iv_image);
        }
        return convertView;
    }

    static class ViewHolder {
        ImageView iv_avatar;
        TextView tv_nickname;
        TextView tv_time;
        ImageView iv_image;
        TextView tv_content;
    }

    public void clear() {
        list.clear();
        notifyDataSetChanged();
    }
}
